package com.example.wangzh.mytest;

import android.graphics.Matrix;
import android.util.Log;
import android.view.View;

import com.example.wangzh.mytest.base.BaseActivity;
import com.example.wangzh.mytest.constant.LogTag;
import com.example.wangzh.mytest.databinding.ActivityMatrixTransformationTestBinding;

public class MatrixTransformationTestActivity extends BaseActivity<ActivityMatrixTransformationTestBinding> {
    @Override
    protected void initView() {
        mBinding.btnMatrixpostInvalid.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d(LogTag.WZH_TEST, "onClick");
                mBinding.view.getMatrix().postTranslate(300, 300);
                mBinding.getRoot().invalidate();
                mBinding.getRoot().requestLayout();
            }
        });
        testPostRotate();
    }

    private void testPostRotate() {
        Matrix matrix = new Matrix();
        matrix.postTranslate(100, 0);       // 平移后原点为 (100,0)
        matrix.postRotate(90, 100, 0);      // 显式指定绕 (100,0) 旋转(这里（100,0）是基于原始坐标系的坐标)

        float[] point = {0, 0};
        matrix.mapPoints(point);
        Log.d(LogTag.WZH_TEST, "testPostRotate.坐标: (" + point[0] + ", " + point[1] + ")");
    }
}
